<!--

/*
#################################################################################
#
# Copyright (c) 2006 Michigan State University
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#################################################################################

#################################################################################
#
#	Author:
#		Nathan Collins <npcollins@gmail.com>
#
#################################################################################
*/

// make a request object
function makeRequestObject() {
	if (window.XMLHttpRequest) {
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		http_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return http_request;
}

// ajax request object
var ajax = makeRequestObject();

// current div id
var divid = '';

// send a request
function sendExpand(toSend,resnum,terms) {
	divid = resnum;
	ajax.open('GET', 'ajax.py?expand='+toSend+'&r=' + resnum + '&s='+terms);
	ajax.onreadystatechange = recvExpand;
	ajax.send(null);
}

function sendShrink(toSend,resnum,terms) {
	divid = resnum;
	ajax.open('GET', 'ajax.py?shrink='+toSend+'&r=' + resnum + '&s='+terms);
	ajax.onreadystatechange = recvShrink;
	ajax.send(null);
}

function sendRemember() {
	ajax.open('GET', 'ajax.py?remember=1');
	ajax.onreadystatechange = function() { recvRemember(); }
	ajax.send(null);
}

function sendHistory() {
	ajax.open('GET', 'ajax.py?history=1');
	ajax.onreadystatechange = recvHistory;
	ajax.send(null);
} 

function sendSuggestDir(parentHash) {
	ajax.open('GET', 'ajax.py?suggestdir=' + parentHash);
	ajax.onreadystatechange = recvSuggestDir;
	ajax.send(null);
}

function sendAR(recID,ar) {
	ajax.open('GET', 'ajax.py?r=' + recID + '&ar=' + ar);
	ajax.onreadystatechange = function() { recvAR(recID) };
	ajax.send(null);
}

function recvAR(recID) {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('subact'+recID,response);
	}
}

function recvSuggestDir() {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('parentSelector',response);
	}
}

function recvExpand() {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement(divid,response);
	}
}

function recvShrink() {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement(divid,response);
	}
}

function recvHistory() {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('historyFloat',response);
		/* bit of a bad hack */
		sendRemember();
	}
}

function recvRemember() {
	if (ajax.readyState == 4 && ajax.status == 200) {
		var response = ajax.responseText;
		updateElement('remembermaster', response);
		addBorder();
		swapArrow();
	}
}

function updateElement(elemName,updateText) {
	document.getElementById(elemName).innerHTML = updateText;
}

//-->
